package com.yinshan.printer.bean;

import android.os.Parcel;
import android.os.Parcelable;

public class PrintData implements Parcelable {
    private int type;
    private String text;
    private Font textSize;
    private boolean isBold;
    private Align textAlign;

    public PrintData(String text, Font textSize, boolean isBold, Align textAlign) {
        this.text = text;
        this.textSize = textSize;
        this.isBold = isBold;
        this.textAlign = textAlign;
    }

    private PrintData(Parcel in) {
        type = in.readInt();
        text = in.readString();
        textSize = in.readParcelable(Font.class.getClassLoader());
        isBold = in.readByte() != 0;
        textAlign = in.readParcelable(Align.class.getClassLoader());
    }

    public static final Creator<PrintData> CREATOR = new Creator<PrintData>() {
        @Override
        public PrintData createFromParcel(Parcel in) {
            return new PrintData(in);
        }

        @Override
        public PrintData[] newArray(int size) {
            return new PrintData[size];
        }
    };

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Font getTextSize() {
        return textSize;
    }

    public void setTextSize(Font textSize) {
        this.textSize = textSize;
    }

    public boolean isBold() {
        return isBold;
    }

    public void setBold(boolean bold) {
        isBold = bold;
    }

    public Align getTextAlign() {
        return textAlign;
    }

    public void setTextAlign(Align textAlign) {
        this.textAlign = textAlign;
    }

    @Override
    public String toString() {
        return "\"PrintData\": {" +
                "\"type\": \"" + type + '\"' +
                "\"text\": \"" + text + '\"' +
                ", \"textSize\": \"" + textSize +
                ", \"isBold\": \"" + isBold +
                ", \"textAlign\": \"" + textAlign +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeString(text);
        dest.writeParcelable(textSize, flags);
        dest.writeByte((byte) (isBold ? 1 : 0));
        dest.writeParcelable(textAlign, flags);
    }

    public enum Font implements Parcelable {
        BIG(0), NORMAL(1), SMALL(2);

        private int value;

        Font(int value) {
            this.value = value;
        }

        public static final Creator<Font> CREATOR = new Creator<Font>() {
            @Override
            public Font createFromParcel(Parcel in) {
                return Font.values()[in.readInt()];
            }

            @Override
            public Font[] newArray(int size) {
                return new Font[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(value);
        }
    }

    public enum Align implements Parcelable {
        LEFT(0), CENTER(1), RIGHT(2);

        private int value;

        Align(int value) {
            this.value = value;
        }

        public static final Creator<Align> CREATOR = new Creator<Align>() {
            @Override
            public Align createFromParcel(Parcel in) {
                return Align.values()[in.readInt()];
            }

            @Override
            public Align[] newArray(int size) {
                return new Align[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(value);
        }
    }
}
